package Spackage;

class Tortoise extends Thread
{
    int sleepTime = 0, liveLength = 0;

    Tortoise(int sleepTime, String name, int liveLength)
    {
        this.sleepTime = sleepTime;
        this.liveLength = liveLength;
        setName(name); // 设置线程的名字name
    }

    public void run()
    {
        while (true)
        {
            liveLength--;
            System.out.printf("@");
            try
            {
                Thread.sleep(sleepTime); // 让线程调用sleep()方法进入中断状态，sleepTime毫秒后线程重新排队，等待CPU资源
            }
            catch (InterruptedException e)
            {
                // 处理中断异常
            }
            if (liveLength <= 0)
            {
                System.out.printf(getName() + "进入死亡状态\n");
                return; // 结束run()方法的语句
            }
        }
    }
}
